package com.cryptoneedle.garden.entity.source.metadata;


import cn.hutool.v7.core.bean.BeanUtil;
import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.garden.key.source.metadata.ServerKey;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

/**
 * <p>description: 源数据源-服务器 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-19
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "source_server")
@IdClass(ServerKey.class)
@Comment("源数据源-服务器")
public class SourceServer extends BaseEntity {

    @Id
    @Comment("服务器-主机")
    private String host;
    @Id
    @Comment("服务器-端口")
    private Integer port;

    @Comment("服务器-可连接")
    private Boolean serverConnected;
    @Comment("服务器-最后可连接时间")
    private Date serverConnectedDt;

    /**
     * Key
     */

    public ServerKey serverKey() {
        return BeanUtil.copyProperties(this, ServerKey.class);
    }

    public String inetAddress() {
        return this.host + ":" + this.port;
    }
}
